import Immutable from 'seamless-immutable';
import * as types from '../constants/ActionTypes';

const testPackage = Immutable.from({
  uploadData: {},
  testPackageList: {},
  uploadPrepress: {},
  testPackageMsg: {},
  uploadMsg:{},
  oneTestPackage: {}
});
export default function testPackageReducer(state = testPackage, action) {
  switch (action.type) {
    case types.FETCH_TEST_PACKAGE:
      return state.setIn(['testPackageList'], action.payload);
    case types.GET_ONE_TEST_PACKAGE:
      return state.setIn(['oneTestPackage'], action.payload);
    case types.UPLOAD_PROPRESS:
      return state.setIn(['uploadPrepress'], action.payload);
    case types.UPLOAD_TEST_PACKAGE:
      return state.setIn(['uploadData'], action.payload);
    case types.CANCEL_UPLOAD:
      return state.setIn(['uploadPrepress'], {});
    case types.RESET_UPLOAD_PROPRESS:
      return state.setIn(['uploadPrepress'], {});
    case types.SAVE_TEST_PACKAGE_ERROR_MSG:
      return state.setIn(['testPackageMsg'], action.payload);
    case types.UPLOAD_ERROR_MSG:
      return state.setIn(['uploadMsg'], action.payload)
        .setIn(['uploadPrepress'], {});
    case types.RESET_UPLOAD_ERROR_MSG:
      return state.setIn(['uploadMsg'], {})
        .setIn(['uploadPrepress'], {});
    case types.RESET_UPLOAD_DATA:
      return state.setIn(['uploadData'], {});
    case types.RESTORE_TEST_PACKAGE:
      return state.setIn(['uploadData'], {})
        .setIn(['uploadPrepress'], {})
        .setIn(['testPackageMsg'], {})
        .setIn(['uploadMsg'], {})
        .setIn(['oneTestPackage'], {})
        .setIn(['uploadButton'], true);
    default:
      return state;
  }
}
